var http=require('http');
var argvArr=process.argv;
var fs=require('fs');
var path=require('path');

var fileName=argvArr[2];


http.createServer((req,res)=>{
    if(fileName){
        var filePath=path.join(__dirname,'/'+fileName);
        fs.readFile(filePath,(err,data)=>{
            if(err){
                console.log(err);
            }else{
                // console.log(data);
                res.end(data);
            }
        })
    }else{
        var filePath=path.join(__dirname,'/fileReader1.js');
        fs.readFile(filePath,(err,data)=>{
            if(err){
                console.log(err);
            }else{
                // console.log(data);
                res.end(data);
            }
        })
    }
    
}).listen(8081);
console.log('sever is listening 8081');
// 如果有乱码，告诉请求头
// res.writeHead(200,{"Content-Type":"text/html;charest=utf-8"})